<?php
//error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR);
require('./roots.php');
require($root_path.'include/inc_environment_global.php');

/**
* CARE2X Integrated Hospital Information System beta 2.0.1 - 2004-07-04
* GNU General Public License
* Copyright 2002,2003,2004,2005,2006 Elpidio Latorilla
* elpidio@care2x.org, 
*
* See the file "copy_notice.txt" for the licence notice
*/
//var_dump($_SESSION['roles']);
$lang_tables[]='interconsulta.php';
define('LANG_FILE','history.php');

require_once($root_path.'include/inc_front_chain_lang.php');
//var_dump($_SESSION['roles']);
$thisfile=basename(__FILE__);
$breakfile=$root_path.'modules/registration_admission/registration_admission.php';

require_once($root_path.'include/care_api_classes/class_core.php');
$core=new Core;

require_once($root_path.'include/care_api_classes/class_gui_history.php');

$ficha=$_GET['ficha'];
$pid=$_GET['pid'];
if( ($pid==NULL)&&($ficha!=NULL)){
	header ("Location: historia_clinica.php?sid=$sid&lang=$lang"); 
}
$s=0;

$guihistory = new GuiHistory($ficha);
$campos = $guihistory->getAllDataObject($ficha, $pid);



// echo '<pre>';
// var_dump($campos);
// echo '</pre>';

# Start Smarty templating here
/**
* LOAD Smarty
*/

# Note: it is advisable to load this after the inc_front_chain_lang.php so
# that the smarty script can use the user configured template theme

require_once($root_path.'gui/smarty_template/smarty_care.class.php');
$smarty = new smarty_care('common');

if (strcmp($ficha, "inmunizaciones"))
{
    if ($campos)
    {
        $smarty->assign('camp',1);
        $i=0;
        $temp=$campos[$i];
        while ($temp!=NULL)
        {
            $gui[] = $temp;
            $i++;
            $temp=$campos[$i];
        }
    }
    else
    {
        $smarty->assign('camp',0);
        $smarty->assign('sNoDisponible', $LDNoDisp);
    }
}
else
{
    if ($campos)
    {
        $smarty->assign('camp',1);
        $inm = "";
        $i = 0;
        $j=0;
        $primera = true;
        $temp=$campos[$j];
        while ($temp!=NULL)
        {
//         var_dump($temp);
//             echo "Empezando wl while con i=$i, inm $inm y temp " . $temp["id_campo"] . "<br>";
            //no la he agregado (es una nueva inmunizacion)
            /*if (!strstr($temp["id_campo"], "clasificacion"))
            {*/
                if (strcmp($inm, $temp["id_campo"]) && $primera)
                {
    //                 echo "primera vez, no son iguales: inm $inm y temp " . $temp["id_campo"] . "<br>";
                	$inm = $temp["id_campo"];
                    $gui[$i]["inm"] = $inm;
                    $primera = false;
                }
                //no la he agregado (es una nueva inmunizacion)
                if (strcmp($inm, $temp["id_campo"]))
                {
    //                 echo "no son iguales: inm $inm y temp " . $temp["id_campo"] . "<br>";
                    $inm = $temp["id_campo"];
                    $i++;
                    $gui[$i]["inm"] = $inm;
                }
				
                $gui[$i]["fechas"][] = $temp;
                $j++;
                $temp=$campos[$j];
            //}
        }
//         echo "<pre>";
//        var_dump($gui);
//         echo "</pre>";
    }
    else
    {
        $smarty->assign('camp',0);
        $smarty->assign('sNoDisponible', $LDNoDisp);
    }
}

$smarty->assign('breakfile',$breakfile);
$smarty->assign('action',$action);
$smarty->assign('ficha',$ficha);
$smarty->assign('pid',$pid);
$smarty->assign('pos',1);
$smarty->assign('root_path', $root_path);

$smarty->assign('sToolbarTitle',$LDHC);

$smarty->assign('title',${'LD' . $ficha});
$smarty->assign('sAccion',$LDAction);
$smarty->assign('sFecha',$LDDate);
$smarty->assign('img', createLDImgSrc($root_path,'ok_small.gif','0'));
$smarty->assign('img2', createLDImgSrc($root_path,'add_sm.gif','0'));
$smarty->assign('append', URL_APPEND);
//var_dump($gui);
$smarty->assign('gui',$gui);

ob_start();
require('../registration_admission/gui_bridge/default/gui_patient_his_options.php');

$tab_bot_line='#66ee66';
require('./gui_bridge/default/gui_tabs_patreg.php');

$sTemp = ob_get_contents();
ob_end_clean();

$smarty->assign('sRegOptions',$sTemp);

$smarty->assign('sMainBlockIncludeFile','historia_clinica/historia_clinica-listar.tpl');

 /**
 * show Template
 */
$smarty->display('common/mainframe.tpl');
?>
